package com.hx.portal.controller.hospital;

import com.alibaba.dubbo.config.annotation.Reference;
import com.hx.common.exception.MessageCode;
import com.hx.common.result.PageResult;
import com.hx.common.result.Result;
import com.hx.hospital.pojo.Yuyue;
import com.hx.hospital.service.YuyueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/yuyue")
@Api(description = "预约相关接口")
public class YuyueController {

    @Reference
    private YuyueService yuyueService;

    @GetMapping("/findYuyueAllByUserId")
    @ApiOperation(value = "查询所有预约信息",notes = "查询所有预约信息",httpMethod = "GET")
    public List<Yuyue> findYuyueAll(Long userId){
        return yuyueService.findYuyueAll(userId);
    }

    @GetMapping("/findYuyueById")
    @ApiOperation(value = "根据id查询预约信息",notes = "根据id查询预约信息",httpMethod = "GET")
    public List<Yuyue> findYuyueById(Long userId){
        return yuyueService.findYuyueById(userId);
    }


    @GetMapping("/findAll")
    public List<Yuyue> findAll(){
        return yuyueService.findAll();
    }

    @GetMapping("/findPage")
    public PageResult<Yuyue> findPage(int page, int size){
        return yuyueService.findPage(page, size);
    }

    @PostMapping("/findList")
    public List<Yuyue> findList(@RequestBody Map<String,Object> searchMap){
        return yuyueService.findList(searchMap);
    }

    @PostMapping("/findPage")
    public PageResult<Yuyue> findPage(@RequestBody Map<String,Object> searchMap,int page, int size){
        return  yuyueService.findPage(searchMap,page,size);
    }

    @GetMapping("/findById")
    public Yuyue findById(Long id){
        return yuyueService.findById(id);
    }


    @PostMapping("/add")
    @ApiOperation(value = "添加预约信息",notes = "添加预约信息",httpMethod = "POST")
    public Result add(@RequestBody Yuyue yuyue){
        if (yuyue.getReceptionCapacity()>=0) {
            yuyue.setReceptionCapacity(yuyue.getReceptionCapacity()-1);
            yuyue.setYuyueState(0L);

            yuyueService.add(yuyue);
        }else {

            System.out.println(MessageCode.ERROR);
        }
        return new Result();
    }

    @PostMapping("/update")
    @ApiOperation(value = "取消预约",notes = "取消预约",httpMethod = "POST")
    public Result update(@RequestBody Yuyue yuyue){
        yuyue.setReceptionCapacity(yuyue.getReceptionCapacity()+1);
        yuyue.setYuyueState(1L);
        yuyueService.update(yuyue);
        return new Result();
    }

    @GetMapping("/delete")
    public Result delete(Long id){
        yuyueService.delete(id);
        return new Result();
    }

}
